//
//  GuideViewController.m
//  SinaWeiBo
//
//  Created by 姚建强 on 15-2-8.
//  Copyright (c) 2015年 com.yjq. All rights reserved.
//

#import "GuideViewController.h"
#import "TabController.h"
@interface GuideViewController ()<UIScrollViewDelegate>
{
    UIScrollView *scrollView;
    UIPageControl *pageControl;
}
@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)beginUse:(UIButton *)sender {
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    [myDefaults setBool:YES forKey:@"guide_pass"];//设置跳过引导界面
    [myDefaults synchronize];//更新
    
    TabController *tabController=[[TabController alloc]init];
    [self presentViewController:tabController animated:YES completion:nil];
}

+(id)guideViewControllerFrame:(CGRect)frame{
   
    return  [[self alloc]initWithFrame:frame ];
}
-(id)initWithFrame:(CGRect)frame{
    self=[super init];
   
    if (self) {
        
        self.view.frame=frame;
        //scrollview全屏显示
        scrollView=[[UIScrollView alloc]initWithFrame:frame];
        NSArray *nibArray=[[NSBundle mainBundle] loadNibNamed:@"Guide" owner:self options:nil];
        NSInteger pageSize=[nibArray count];
        for ( int i=0; i<pageSize; i++) {
                UIView *scrollSubView= nibArray[i];
            scrollSubView.frame=CGRectMake(frame.size.width*i, 0, frame.size.width, frame.size.height);
            [scrollView addSubview:scrollSubView];
        }
        [scrollView setDelegate:self];
        //设置scrollview内部可拉伸大小
        [scrollView setContentSize:CGSizeMake(frame.size.width*pageSize,frame.size.height )];
        //设置scrollview分页显示
        [scrollView setPagingEnabled:YES];
        //取消弹性拉伸
        [scrollView setBounces:NO];
        //隐藏水平滚动条
        [scrollView setShowsHorizontalScrollIndicator:NO];
        pageControl =[[UIPageControl alloc]init];
        //使剧中
        pageControl.center=CGPointMake(frame.size.width/2.0, frame.size.height/6*4);
        //宽度为屏幕一半，高度为6分之1
        pageControl.bounds=CGRectMake(0, 0, frame.size.width/2, frame.size.height/6);
        pageControl.numberOfPages=pageSize;//总页数
        pageControl.currentPage=0; //初始页数为0
        pageControl.currentPageIndicatorTintColor=[UIColor orangeColor];//设置被选择的点的颜色
        pageControl.pageIndicatorTintColor=[UIColor grayColor];//设置未被选择的点的颜色
        pageControl.enabled=NO;//pageControl点击无效
        [self.view addSubview:scrollView];
        [self.view addSubview:pageControl];
    }

    return self;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
        //当scrollview翻页时，设置当前页
        pageControl.currentPage=scrollView.contentOffset.x/scrollView.frame.size.width;
    
}
@end
